package codeTopPractice.sortedPractice;

import java.util.Arrays;
import java.util.Random;

public class 快排 {

    public static void main(String[] args) {

        int[] array =new int[]{5,8,6,2,5,7,3,1,5,3,96,98};
        quickSorted(array,0,array.length-1);
        for (int i = 0; i < array.length ; i++) {
            System.out.println(array[i]);
        }

    }

    public static void quickSorted(int[] array,int l,int r){

        if(l >= r){
            return;
        }

        int start = l;
        int end = r;

        int key = array[l];

        while (end > start) {
            while (end > start && array[end] >= key) end--;
            while (end > start && array[start] <= key) start++;
                int temp = array[end];
                array[end] = array[start];
                array[start] = temp;

        }
            array[l] = array[end];
            array[end] = key;

            quickSorted(array,l,start-1);
            quickSorted(array,end+1,r);
    }

}
